package org.yn.user.controller;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yn.auth.annotation.PermissionAnnotation;
import org.yn.base.util.AjaxResult;
import org.yn.user.dto.BindSendSmsCodeDTO;
import org.yn.user.dto.RegisterSendSmsCodeDTO;
import org.yn.user.service.VerifyCodeService;

import javax.validation.Valid;
import java.io.IOException;

@PermissionAnnotation(name="用户登信息管理",descs = "用户登信息管理api")
@Api("用户登信息管理接口")
@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    VerifyCodeService verifyCodeService;

    /**
     *
     * @return
     */
    @GetMapping("/image/{imageCodeKey}")
    public AjaxResult getVerifyCode(@PathVariable("imageCodeKey") String imageCodeKey) throws IOException {
      String ImageBase64=  verifyCodeService.getImage(imageCodeKey);

        return AjaxResult.success(ImageBase64);
    }

    @PostMapping("/sms/register")
    public AjaxResult registerSendSmsCode(@Valid @RequestBody RegisterSendSmsCodeDTO dto){
        verifyCodeService.registerSendSmsCode(dto);
        return AjaxResult.success();
    }


    /**
     *
     * @param dto
     * @return
     */
    @PostMapping("/sms/bind")
    public AjaxResult bindSendSmsCode(@Valid @RequestBody BindSendSmsCodeDTO dto){
        
        verifyCodeService.bindSendSmsCode(dto);
        return AjaxResult.success();
    }
}
